import Layout from '@/views/layout/Layout'
import userManage from '@/views/function/user'
import { mapGetters, mapActions } from "vuex"
const router_min = [
    [{

        path: '/components', //這裏不用跳轉
        meta: { title: '系统管理模块', icon: 'example' },
        component: () => import('@/views/layout/Layout'),
        children: []
    }],

    [{

        path: '/components', //這裏不用跳轉
        meta: { title: '安全管理模块', icon: 'example' },
        component:Layout,
        children: []
    }],

    [{

        path: '/components', //這裏不用跳轉
        meta: { title: '业务办理模块', icon: 'example' },
        component:Layout,
        children: []
    }],
    [{
        meta: { title: '审计日志模块', icon: 'example' },
        path: '/components', //這裏不用跳轉
        component: () => import('@/views/layout/Layout'),
        children: []
    }],

]


// 这个是路由，不是sidebar的层级，路由嵌套是为了适配父子组件。
export const router_full =
    [

        {
            name: '系统管理模块',
            icon: 'el-icon-setting',
            path: '/components', //這裏不用跳轉
            component: () => import('@/views/layout/Layout'),
            children: [
                {
                    path: 'user',
                    meta: { title: '用户管理', icon: 'user' },
                    component: () =>  import('@/views/function/user'),
                    code: 'A0002'
                },
                {
                    path: 'admin/role',
                    meta: { title: '角色管理', icon: 'tree' },
                    component: () => import('@/views/function/role'),
                    code: 'A0002'
                },
                {
                    path: 'admin/permission',
                    meta: { title: '权限设置', icon: 'table' },
                    component: () => import('@/views/function/permission'),
                    code: 'A0009'
                },
                {

                    path: 'admin/userlockstatus',
                    meta: { title: '账号锁定管理', icon: 'password' },
                    component: () => import('@/views/function/safeconfig/userlockstatus'),
                    code: 'A0009'
                },
                {
                    path: 'admin/userterminalband',
                    meta: { title: '账号终端绑定策略', icon: 'nested' },
                    component: () => import('@/views/function/safeconfig/userterminalband'),
                    code: 'A0009'
                },
                {
                    path: 'admin/useractivestatus',
                    meta: { title: '账号失效管理', icon: 'nested' },
                    component: () => import('@/views/function/safeconfig/useractivestatus'),
                    code: 'A0009'
                },
                {
                    path: 'admin/interface_server_config',
                    meta: { title: '接口服务器管理', icon: 'link' },
                    component: () => import('@/views/function/manaconfig/interface_server_config'),
                    code: 'A0009'
                },
                {
                    path: 'admin/interface_check_config',
                    meta: { title: '接口服务器检测设置', icon: 'eye' },
                    component: () => import('@/views/function/manaconfig/interface_check_config'),
                    code: 'A0009'
                },
                {
                    path: 'admin/border_check_config',
                    meta: { title: '边界服务器检测设置', icon: 'example' },
                    component: () => import('@/views/function/manaconfig/border_check_config'),
                    code: 'A0009'
                },

            ]
        },
        {
            name: '安全管理模块',
            icon: 'el-icon-bell',
            path: '/components', //這裏不用跳轉
            component: () => import('@/views/layout/Layout'),
            children: [
                {
                    name: "用户安全策略",
                    icon: 'al-icon-SanMiAppiconfill5',
                    path: '/components', //這裏不用跳轉
                    component: () => import('@/views/layout/Layout'),
                    children: [
                        {
                            path: '/components/userloginfailedpolicy',
                            meta: { title: '用户登录失败策略', icon: 'table' },
                            component: () => import('@/views/function/safeconfig/userloginfailedpolicy'),
                            code: 'A0009'
                        },
                        {
                            path: '/components/userexpirationpolicy',
                            meta: { title: '账号有效期策略', icon: 'table' },
                            component: () => import('@/views/function/safeconfig/userexpirationpolicy'),
                            code: 'A0009'
                        },
                        {
                            path: '/components/passwordexpirationpolicy',
                            meta: { title: '边界服务器检测设置', icon: 'table' },
                            component: () => import('@/views/function/safeconfig/passwordexpirationpolicy'),
                            code: 'A0009'
                        },
                        {
                            path: '/components/usernotusedforlongtimepolicy',
                            meta: { title: '账号有效期策略', icon: 'table' },
                            component: () => import('@/views/function/safeconfig/usernotusedforlongtimepolicy'),
                            code: 'A0009'
                        },
                        {
                            path: '/components/userloginallowtime',
                            meta: { title: '账号允许登录时间', icon: 'table' },
                            component: () => import('@/views/function/safeconfig/userloginallowtime'),
                            code: 'A0009'
                        },
                        {
                            path: '/components/highFrequencyLogin',
                            meta: { title: '用户高频登录策略', icon: 'table' },
                            component: () => import('@/views/function/safeconfig/highFrequencyLogin'),
                            code: 'A0009'
                        }
                    ]
                },

                {

                    path: '/components',
                    meta: { title: '终端安全策略', icon: 'table' },
                    component: () => import('@/views/layout/Layout'),
                    children: [
                        {
                            path: '/components/terminalloginfailedpolicy',
                            meta: { title: '终端登录失败策略', icon: 'table' },
                            component: () => import('@/views/function/safeconfig/terminalloginfailedpolicy'),
                            code: 'A0009'
                        }
                    ]
                },

                {
                    name: "系统安全策略",
                    icon: 'al-icon-buduandian',
                    path: '/components',
                    component: () => import('@/views/layout/Layout'),
                    children: [
                        {
                            path: '/components/maxonlinepeople',
                            meta: { title: '最大在线人数配置', icon: 'table' },
                            component: () => import('@/views/function/safeconfig/maxonlinepeople'),
                            code: 'A0009'
                        },
                        {
                            path: '/components/sessiontimepolicy',
                            meta: { title: '系统会话时长配置', icon: 'table' },
                            component: () => import('@/views/function/safeconfig/sessiontimepolicy'),
                            code: 'A0009'
                        }
                    ]

                },

                {
                    name: '异常状态管理',
                    path: '/terminallockstatus',
                    meta: { title: '异常状态管理', icon: 'table' },
                    component: () => import('@/views/layout/Layout'),
                    children: [

                        {
                            path: '/components/terminallockstatus',
                            meta: { title: '终端锁定管理', icon: 'table' },
                            component: () => import('@/views/function/safeconfig/terminallockstatus'),
                            code: 'A0009'
                        }
                    ]
                }
            ]
        },

        {
            name: '业务办理模块',
            icon: 'el-icon-tickets',
            path: '/components', //這裏不用跳轉
            component: () => import('@/views/layout/Layout'),
            children: [
                {
                    path: '/components/driverInfoQuery',
                    meta: { title: '驾驶员信息查询', icon: 'user' },
                    component: () => import('@/views/function/transaction/driverInfoQuery'),
                    code: ''
                },
                {
                    path: '/components/driverLicenseQuery',
                     meta: { title: '驾驶证信息查询', icon: 'user' },
                    component: () => import('@/views/function/transaction/driverLicenseQuery'),
                    code: ''
                },
                {
                    path: '/components/carInfoQuery',
                    meta: { title: '机动车信息查询', icon: 'user' },
                    component: () => import('@/views/function/transaction/carInfoQuery'),
                    code: ''
                },
                {
                    path: '/components/carViolationQuery',
                    meta: { title: '处罚决定书处理', icon: 'user' },
                    component: () => import('@/views/function/transaction/carViolationQuery'),
                    code: ''
                },
                {

                    path: '/components/SurveilTextQuery',
                    meta: { title: '电子警察处理', icon: 'user' },
                    component: () => import('@/views/function/transaction/SurveilTextQuery'),
                    code: ''
                },
                {
                    path: '/components/logQuery',
                    meta: { title: '决定书处理日志', icon: 'user' },
                    component: () => import('@/views/function/transaction/logQuery'),
                    code: ''
                },
                {
                    path: '/components/bankReconcilationQuery',
                    meta: { title: '银行对账信息查询', icon: 'user' },
                    component: () => import('@/views/function/transaction/bankReconcilationQuery'),
                    code: ''
                },
                {

                    path: '/components/certifyDriverQuery',
                    meta: { title: '驾驶人车辆核查查询', icon: 'user' },
                    component: () => import('@/views/function/transaction/certifyDriverQuery'),
                    code: ''
                },
                {
                    path: '/components/trafficCodeQuery',
                    meta: { title: '违法行为代码查询', icon: 'user' },
                    component: () => import('@/views/function/transaction/trafficCodeQuery'),
                    code: ''
                },
                {
                    path: '/components/transactionLogQuery',
                    meta: { title: '业务操作日志查询', icon: 'user' },
                    component: () => import('@/views/function/transaction/transactionLogQuery'),
                    code: ''
                },
                {
                    path: '/components/terminal_userinfo',
                    meta: { title: '终端实名用户信息查询', icon: 'user' },
                    component: () => import('@/views/function/transaction/terminal_userinfo'),
                    code: ''
                },
                {
                    path: '/components',
                    meta: { title: '业务查询统计', icon: 'user' },
                    component: () => import('@/views/layout/Layout'),
                    code: '',
                    children:[
                        {
                            path: '/components/punishment_release',
                            meta: { title: '处罚及解档情况查询', icon: 'user' },
                            component: () => import('@/views/function/inquire/punishment_release'),
                            code: ''
                        },
                        {
                            path: '/components/toll_happening',
                            meta: { title: '收费情况查询', icon: 'user' },
                            component: () => import('@/views/function/inquire/toll_happening'),
                            code: ''
                        },
                        {
                            path: '/components/punishment_release',
                            meta: { title: '数据同步情况查询', icon: 'user' },
                            component: () => import('@/views/function/inquire/data_synchronize'),
                            code: ''
                        },
                        {
                            path: '/components/punishment_release',
                            meta: { title: '已经处理的违章', icon: 'user' },
                            component: () => import('@/views/function/inquire/dealwith_violation'),
                            code: ''
                        }
                    ]
                },
            ]
        },
        {
            name: '审计日志模块',
            icon: 'el-icon-edit',
            path: '/components', //這裏不用跳轉
            component: () => import('@/views/layout/Layout'),
            children: [
                {
                    path: '/components/loginlog',
                    meta: { title: '用户登陆日志', icon: 'table' },
                    component: () => import('@/views/function/loginfo/loginlog'),
                    code: 'D0001'
                },
                {
                    path: '/components/operlog',
                    meta: { title: '用户操作日志', icon: 'table' },
                    component: () => import('@/views/function/loginfo/operlog'),
                    code: 'D0003'
                },
                {

                    path: '/components/securitylog',
                    meta: { title: '用户安全日志', icon: 'table' },
                    component: () => import('@/views/function/loginfo/securitylog'),
                    code: 'D0002'
                },
                {
                    path: '/components/loggerSaveTime',
                    meta: { title: '日志存储期限策略', icon: 'table' },
                    component: () => import('@/views/function/safeconfig/loggerSaveTime'),
                    code: 'D0004'
                }
            ]
        }
    ]

export function login(userName, password) {
    return HTTP.methods.apiPost(
        '/user/login.shtml',{
            userName,
            password
        }
    )
}

export function getInfo(token) {
    return HTTP.methods.apiGet( '/user/info',token)
}

// 注释...需要补充
function arrcc(permission, id) {
    var arr = router_min[id] // 这里的0是不对的，其他分支怎么办？按id来走条件判断才行
    for (let i of permission) {
        for (let j = 0; j < router_full[id].children.length; j++) {
            if (router_full[id].children[j].code == i) {
                arr[0].children.push(router_full[id].children[j])
                // 下面是有child嵌套child的情况
                if ('children' in router_full[id].children[j]) {
                    for (let k = 0; j < router_full[id].children[j].children[k].length; k++) {
                        arr[0].children[j].children.push(router_full[id].children[j].children[k])
                    }
                }
            }
        }
    }
    return arr
}
//WJ：从全量路由对象数组中，得到对应当前用户权限code的元，并添加进入到用户当前路由
export function filterRouter(permission, id) {
    // console.log(permission[0].substring(0,1),'permission[0]')
    // console.log(Standard,'Standard')
    switch (id) {
        case "A":     //系统管理模块
            return arrcc(permission, id = 0)
            break;
        case "B":
            return arrcc(permission, id = 1)
            break;
        case "D":
            return arrcc(permission, id = 2)
            break;
        case "C":       //审计管理员
            return arrcc(permission, id = 3)
            break;
        default:
    }
}
